package GUI.gameWinOld;

import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;

import GUI.CardImages;
import carddeck.Card;
import carddeck.Rank;
import carddeck.Suit;

@SuppressWarnings("serial")
public class JokerSelectionButton extends CardButton {
	private int val;
	private String cardString;
	private Card theCard;
	private JokerSelectionDialog owner;
	public JokerSelectionButton(JokerSelectionDialog dlg, Card card) {
		super();
		owner=dlg;
		theCard=card;
		setBorder(BorderFactory.createEmptyBorder());
		setContentAreaFilled(false);
		
		val=card.getCardRank().getValue();
		Suit cardSuit=card.getCardSuit();
		if(cardSuit==Suit.HEARTS)
			;
		else if(cardSuit==Suit.DIAMONDS)
			val+=13;
		else if(cardSuit==Suit.CLUBS)
			val+=26;
		else if(cardSuit==Suit.SPADES)
			val+=39;
		else//Joker
			val=0;
		cardString = "/carddeck/conv/resized";
			if(card.getCardRank()==Rank.KING)
				cardString+="H/";
			else
				cardString+="H/cutH/";
			ImageIcon img;
			if(card.getCardRank()==Rank.KING)
				img = CardImages.getInstance().getII(cardString+val);
			else
				img = CardImages.getInstance().getII(cardString+val);
			setIcon(img);
			addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					selectCardActionPerformed(evt);
				}
			});
	}
	
	public void setHighlighted(boolean hl) {
		ImageIcon img;
		if(!hl) {
			if(theCard.getCardRank()==Rank.KING)
				img = CardImages.getInstance().getII(cardString+val);
			else
				img = CardImages.getInstance().getII(cardString+val);
			setIcon(img);
		}
		else {
			img = CardImages.getInstance().getII(cardString+"HL_B/"+val);
			setIcon(img);
		}
	}
	
	public Card getCard() {
		return theCard;
	}
	
	public void selectCardActionPerformed(ActionEvent evt) {
		if(owner.getSelected()!=theCard) {
			owner.select(theCard, this);
			setHighlighted(true);
		}
		else {
			owner.deselect();
			setHighlighted(false);
		}
	}
}
